/*
 * Powered By dico
 * Since 2017 - 2018
 */package com.seeyoui.kensite.bussiness.orderlang.product.service;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.common.base.service.BaseService;

import java.util.*;

import com.seeyoui.kensite.common.base.domain.EasyUIDataGrid;
import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.common.exception.CRUDException;
import com.seeyoui.kensite.common.util.*;
import com.seeyoui.kensite.common.constants.StringConstant;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.Product;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.ProductCusIndexVO;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.ProductQueryDTO;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.ProductVO;
import com.seeyoui.kensite.bussiness.orderlang.product.persistence.ProductMapper;

/**
 * Product
 * @author dico
 * @version 2.0
 * @since 1.0
 * @date 2018-02-07
 */

@Service
public class ProductService extends BaseService {
	
	@Autowired
	private ProductMapper productMapper;

	/**
	 * 根据ID查询单条数据
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public Product findOne(String id) throws CRUDException{
		return productMapper.findOne(id);
	}
	
	public List<ProductCusIndexVO> findProductListFirstLevel(String categoryId){
		return productMapper.findProductListFirstLevel(categoryId);
	}
	
	public List<ProductCusIndexVO> findProductListSecondLevel(String categoryId){
		return productMapper.findProductListSecondLevel(categoryId);
	}
	
	public List<ProductCusIndexVO> findProductListThirdLevel(String categoryId){
		return productMapper.findProductListThirdLevel(categoryId);
	}
	
	/**
	 * 根据条件查询商品列表
	 * @param productName
	 * @param isRelease
	 * @param quantity
	 * @param categoryName
	 * @param label
	 * @param sortCondition
	 * @param productQueryDTO
	 * @param page
	 * @param rows
	 * @return
	 */
	public List<ProductVO> findListByCondition(String productName,String isRelease,
			ProductQueryDTO productQueryDTO,int page, int rows) throws CRUDException {
		productQueryDTO.setProductName(productName);
		productQueryDTO.setIsRelease(isRelease);
		productQueryDTO.setPage(page);
		productQueryDTO.setRows(rows);
		List<ProductVO> productList = productMapper.findListByCondition(productQueryDTO);
		return productList;
	}
	
	/**
	 * 根据id查询单个商品
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public ProductVO findProductById(String id) throws CRUDException {
		ProductVO product = productMapper.findProductById(id);
		return product;
	}
	
	/**
	 * 根据id查询商品明细（明细页面）
	 * @param id
	 * @return
	 */
	public ProductVO findProductDetailById(String id){
		return productMapper.findProductDetailById(id);
	}
	
	/**
	 * 查询数据集合
	 * @param product
	 * @return
	 * @throws CRUDException
	 */
	public List<Product> findList(Product product) throws CRUDException {
		return productMapper.findList(product);
	}
	
	/**
     * 出入库查询商品列表
     * @param Map
     * @return
     * @throws CRUDException
     */
    public List<Product> findProductsByKey(Map map) throws CRUDException {
        return productMapper.findProductsByKey(map);
    }
	
	/**
	 * 查询所有数据集合
	 * @param product
	 * @return
	 * @throws CRUDException
	 */
	public List<Product> findAll(Product product) throws CRUDException {
		return productMapper.findAll(product);
	}
	
	/**
	 * 查询数据总数
	 * @param product
	 * @return
	 * @throws CRUDException
	 */
	public int findTotal(Product product) throws CRUDException {
		return productMapper.findTotal(product);
	}
	
	/**
	 * 查询数据总数排除当前数据
	 * @param product
	 * @return
	 * @throws CRUDException
	 */
	public int findExTotal(Product product) throws CRUDException {
		return productMapper.findExTotal(product);
	}
	
	/**
	 * 数据新增
	 * @param product
	 * @throws CRUDException
	 */
	public void save(Product product) throws CRUDException{
		product.preInsert();
		productMapper.save(product);
	}
	
	/**
	 * 数据修改
	 * @param product
	 * @throws CRUDException
	 */
	public void update(Product product) throws CRUDException{
		product.preUpdate();
		productMapper.update(product);			
	}
	
	/**
	 * 数据删除
	 * @param listId
	 * @throws CRUDException
	 */
	public void delete(List<String> listId) throws CRUDException {
		productMapper.delete(listId);
	}
	
	/**
	 * 数据假删除
	 * @param product
	 * @throws CRUDException
	 */
	public void remove(Product product) throws CRUDException{
		product.preUpdate();
		productMapper.remove(product);			
	}
	
}
